package com.wokeMy.view;

import android.app.Dialog;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.woke.MybankblindActivity;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.woke.data.Data_bindcarlist;
import com.woke.data.UnionPayChannel;
import com.woke.method.MyApp;
import com.wokeMy.view.base.BaseActivity;
import com.wokeMy.view.channe.gaohuitong.GhtZfActivity;
import com.wokeMy.view.model.Constant;
import com.wokeMy.view.util.Util;
import com.zhongcai.online.R;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;


public class CreditRepayActivity extends BaseActivity implements View.OnClickListener {

    TextView zfcard_repaycreditard,jscard_repaycredit,dhjl_tv,detail_tv;
    EditText money_repaycreditard_et;
    RelativeLayout zhifu_repaycreditard_rl;
    RelativeLayout jieshuan_repaycredit_rl;
    ImageView back;
    TextView shuom_text_title;
    Button paybt;

    Data_bindcarlist listdata,shoulistdata,paylistdata;
    Intent intent;
    String money;
    int way_id,vip_level;
    String user_id,phone;
    String pay_card_no,card_no,expired_date,cvv,smsCode_bind;
    UnionPayChannel unionPayChannel;
    Dialog mydialog;

    Double yueMoney;
    String card;
    @Override
    public void setContentView() {
        setContentView(R.layout.activity_credit_repay);
    }

    @Override
    public void initActivity() {
        zhifu_repaycreditard_rl.setOnClickListener(this);
        jieshuan_repaycredit_rl.setOnClickListener(this);
        back.setOnClickListener(this);
        shuom_text_title.setOnClickListener(this);
        paybt.setOnClickListener(this);
        dhjl_tv.setOnClickListener(this);
        detail_tv.setOnClickListener(this);
//        money_repaycreditard_et.setText("￥"+money);
//        zctCreditRePay();

    }

    @Override
    public void initView() {
        money_repaycreditard_et = myFindViewById(R.id.money_repaycreditard_et);
        shuom_text_title = myFindViewById(R.id.shuom_text_title);

        zhifu_repaycreditard_rl = myFindViewById(R.id.zhifu_repaycreditard_rl);
        jieshuan_repaycredit_rl = myFindViewById(R.id.jieshuan_repaycredit_rl);
        zfcard_repaycreditard = myFindViewById(R.id.zfcard_repaycreditard);
        jscard_repaycredit = myFindViewById(R.id.jscard_repaycredit);
        back = myFindViewById(R.id.back_repaycreditard_iv);
        paybt = myFindViewById(R.id.pay_repaycredit_bt);
        dhjl_tv = myFindViewById(R.id.dhjl_tv);
        detail_tv = myFindViewById(R.id.detail_tv);
    }

    @Override
    public void initData() {
        intent=getIntent();
        way_id=89;
        //        user_id = intent.getStringExtra("user_id");
        yueMoney=0.00;
        user_id=((MyApp)getApplication()).getDatas_load().getId();
        vip_level=(Integer.parseInt(((MyApp)getApplication()).getDatas_load().getUser_type()));
        //        unionPayChannel=(UnionPayChannel)intent.getSerializableExtra("unionPayChanne");
        //        Log.e("initData",money+" "+unionPayChannel.getId()+" "+unionPayChannel.get)
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_repaycreditard_iv:
                finish();
                break;
            case R.id.shuom_text_title:
                Intent inte = new Intent (CreditRepayActivity.this, RecordCreditActivity.class);
                inte.putExtra ("way_id",way_id);
                startActivity(inte);
//                mydialog=Util.createLoadingDialog(CreditRepayActivity.this);
//                yuesearchSingle();
                break;
            case R.id.pay_repaycredit_bt:
                money=money_repaycreditard_et.getText().toString().trim();
                if((money==null)||money.equals("")){
                    Toast.makeText(CreditRepayActivity.this,"请输入金额",Toast.LENGTH_SHORT).show();
                }else if(card_no==null||card_no.equals("")){
                    Toast.makeText(CreditRepayActivity.this,"收款卡未选择",Toast.LENGTH_SHORT).show();
                } else {
                    mydialog=  Util.createLoadingDialog(CreditRepayActivity.this);
                    yOrder();
                }

////掌财通信用卡还款
//                if((money==null)||money.equals("")){
//                Toast.makeText(CreditRepayActivity.this,"请输入金额",Toast.LENGTH_SHORT).show();
//                }else if(Double.parseDouble(money)<20){
//                    Toast.makeText(CreditRepayActivity.this,"金额必须大于等于20",Toast.LENGTH_SHORT).show();
//                }else if(card_no==null||card_no.equals("")){
//                    Toast.makeText(CreditRepayActivity.this,"收款卡未选择",Toast.LENGTH_SHORT).show();
//                } else {
//                    mydialog=  Util.createLoadingDialog(CreditRepayActivity.this);
////                    if (pay_card_no==null||pay_card_no.equals("")){
////                        zhijietixian();
////                    }else {
////                        chongzhi();
////                    }
//                }
                //                Toast.makeText(CreditRepayActivity.this,"暂未开通",Toast.LENGTH_SHORT).show();
                break;
            case R.id.zhifu_repaycreditard_rl: // 付款卡
                Intent intent = new Intent (CreditRepayActivity.this, MybankblindActivity.class);
                intent.putExtra ("czhiortxian", "creditcard");
                intent.putExtra ("card", "fukuan");
                startActivityForResult (intent, Constant.REQUEST_ZCTCREPLAY);
                break;
            case R.id.jieshuan_repaycredit_rl: // 收款卡
                Intent intent2 = new Intent (CreditRepayActivity.this, MybankblindActivity.class);
                intent2.putExtra ("czhiortxian", "creditcard");
                intent2.putExtra ("card", "shoukuan");
                startActivityForResult (intent2, Constant.REQUEST_ZCTCREPLAY);
                break;
            default:
                break;
        }
    }

//    //商户入网 掌财通信用卡还款
//    private void zctCreditRePay() {
//        AsyncHttpClient ahc = new AsyncHttpClient();
//        RequestParams params = new RequestParams();
//        params.put("user_id",user_id);
//        Log.e("掌财通信用卡还款params",params.toString());
//        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
//        ahc.post(Constant.CREPAYZCT_URL, params, new AsyncHttpResponseHandler() {
//            @Override
//            public void onSuccess(int i, Header[] headers, byte[] bytes) {
//                //判断状态码
//                if(i == 200){
//                    //获取结果
//                        try {
//                            String result = new String(bytes, "utf-8");
//                            //                        Toast.makeText(CreditRepayActivity.this, result, Toast.LENGTH_SHORT).show();
//                            Log.e("掌财通信用卡还款result", result);
//                            try {
//                                JSONObject jsonObject = new JSONObject(result);
//                                if (jsonObject.get("flag").equals("success")) {
//                                    String status = jsonObject.getJSONObject("data").getJSONObject("data").getString("status");
//                                    if (status.equals("00")){
////                                        yuesearch();
//                                    }else {
//                                        Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//                                    }
//                                } else {
//                                    if (jsonObject.getString("info").equals("操作失败")) {
//                                        if (jsonObject.getString("data")==null||jsonObject.getString("data").equals("")){
//                                            Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//
//                                        }else {
//                                            String message = jsonObject.getJSONObject("data").getJSONObject("data").getString("message");
//                                            Toast.makeText(CreditRepayActivity.this, message, Toast.LENGTH_LONG).show();
//                                        }
//
//                                    } else {
//                                        Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//                                    }
//
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//
//                        } catch (UnsupportedEncodingException e) {
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        }
//                    }
//            }
//
//            @Override
//            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
//                Util.closeDialog(mydialog);
//            }
//        });
//    }
//    //掌财信用卡还发送短信（断有没有开通过快捷支付）
//    private void bindsendm() {
//        AsyncHttpClient ahc = new AsyncHttpClient();
//        RequestParams params = new RequestParams();
//        params.put("user_id",user_id);
//        params.put("phone",phone);//选中卡的手机号
//        params.put("card_no",card);////选择的卡号 (支付卡)
//        params.put("expired_date",expired_date);//选中的卡有效期
//        params.put("cvv",cvv);//选中卡背面后三位
//        Log.e("掌财信用卡发送短信params",params.toString());
//        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
//        ahc.post(Constant.BINDSMSZCT_URL, params, new AsyncHttpResponseHandler() {
//            @Override
//            public void onSuccess(int i, Header[] headers, byte[] bytes) {
//                Util.closeDialog(mydialog);
//                //判断状态码
//                if(i == 200){
//                    //获取结果
//                        try {
//                            String result = new String(bytes, "utf-8");
//                            //                        Toast.makeText(CreditRepayActivity.this, result, Toast.LENGTH_SHORT).show();
//                            Log.e("掌财信用卡发送短信Result", result);
//                            try {
//                                JSONObject jsonObject = new JSONObject(result);
//                                if (jsonObject.get("flag").equals("success")) {
//                                    String status = jsonObject.getJSONObject("data").getJSONObject("data").getString("bindstatus");
//                                    if (status.equals("00")){
//                                        String bindid = jsonObject.getJSONObject("data").getJSONObject("data").getString("bindid");
//                                        String userno = jsonObject.getJSONObject("data").getJSONObject("data").getString("userno");
//                                        Intent intent =new Intent(CreditRepayActivity.this, CjSlyzmActivity.class);
//                                        intent.putExtra("jiemian","creditRepay");
//                                        intent.putExtra("bindid",bindid);
//                                        intent.putExtra("userno",userno);
//                                        intent.putExtra("user_id",user_id);
//                                        startActivityForResult (intent, Constant.REQUEST_CJKJZFBIND);
//                                    }else {
//                                        Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//                                    }
//                                } else {
//                                    if (jsonObject.getString("info").equals("操作失败")) {
//                                        if (jsonObject.getString("data")==null||jsonObject.getString("data").equals("")){
//                                            Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//                                        }else {
//                                            String message = jsonObject.getJSONObject("data").getJSONObject("data").getString("message");
//                                            Toast.makeText(CreditRepayActivity.this, message, Toast.LENGTH_LONG).show();
//                                        }
//
//                                    } else {
//                                        Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//                                    }
//
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//
//                        } catch (UnsupportedEncodingException e) {
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        }
//                    }
//            }
//            @Override
//            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
//                Util.closeDialog(mydialog);
//            }
//        });
//    }
//    //掌财信用卡  充值
//    private void chongzhi() {
//        AsyncHttpClient ahc = new AsyncHttpClient();
//        RequestParams params = new RequestParams();
//        params.put("user_id",user_id);
//        params.put("card_no",pay_card_no);////付款卡
//        params.put("amount",money);//金额
//        Log.e("掌财信用卡充值params",params.toString());
//        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
//        ahc.post(Constant.CZZCT_URL, params, new AsyncHttpResponseHandler() {
//            @Override
//            public void onSuccess(int i, Header[] headers, byte[] bytes) {
//                //判断状态码
//                if(i == 200){
//                    //获取结果
//                        try {
//                            String result = new String(bytes, "utf-8");
//                            Log.e("掌财信用卡充值Result", result);
//                            try {
//                                JSONObject jsonObject = new JSONObject(result);
//
//                                if (jsonObject.get("flag").equals("success")) {
//                                    String status=jsonObject.getJSONObject("data").getJSONObject("data").getString("status");
//                                    if (status.equals("SUCCESS")){
//                                        yuesearch();//查询余额
//                                    }else {
//                                        Util.closeDialog(mydialog);
//                                        String statusdesc=jsonObject.getJSONObject("data").getJSONObject("data").getString("statusdesc");
//                                        tishi(statusdesc+"!");
//                                    }
//                                } else {
//                                    Util.closeDialog(mydialog);
//                                    if (jsonObject.getString("info").equals("操作失败")) {
//                                        if (jsonObject.getString("data")==null||jsonObject.getString("data").equals("")){
//                                            Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//
//                                        }else {
//                                            String message = jsonObject.getJSONObject("data").getJSONObject("data").getString("message");
//                                            Toast.makeText(CreditRepayActivity.this, message, Toast.LENGTH_LONG).show();
//                                        }
//
//                                    } else {
//                                        String string = jsonObject.getJSONObject("data").getJSONObject("data").getString("code");
//                                        if (string.equals("110042")){
//                                            flaralogid("提示","交易手续费与用户入网信息不一致");
//                                        }else {
//                                            Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//                                        }
//                                    }
//
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//
//                        } catch (UnsupportedEncodingException e) {
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        }
//                    }
//            }
//
//            @Override
//            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
//                Util.closeDialog(mydialog);
//            }
//        });
//    }
//    //掌财信用卡  成功后提现
//    private void tixian() {
//        AsyncHttpClient ahc = new AsyncHttpClient();
//        RequestParams params = new RequestParams();
//        params.put("user_id",user_id);
//        params.put("card_no",card_no);////付款卡
//        params.put("amount",yueMoney);//选中的卡有效期
//        Log.e("掌财信用卡提现params",params.toString());
//        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
//        ahc.post(Constant.TXZCT_URL, params, new AsyncHttpResponseHandler() {
//            @Override
//            public void onSuccess(int i, Header[] headers, byte[] bytes) {
//                Util.closeDialog(mydialog);
//                //判断状态码
//                if(i == 200){
//                    //获取结果
//                        try {
//                            String result = new String(bytes, "utf-8");
//                            //                        Toast.makeText(CreditRepayActivity.this, result, Toast.LENGTH_SHORT).show();
//                            Log.e("掌财信用卡提现Result", result);
//                            try {
//                                JSONObject jsonObject = new JSONObject(result);
//                                if (jsonObject.get("flag").equals("success")) {
//                                    if (jsonObject.getJSONObject("data").getJSONObject("data").getString("status").equals("FAIL")){
//                                        tishi("代还失败");
//                                    }else {
//                                        Toast.makeText(CreditRepayActivity.this, "信用卡代还成功", Toast.LENGTH_LONG).show();
//                                        finish();
//                                    }
//                                } else {
//                                    if (jsonObject.getJSONObject("data").getJSONObject("data").getString("code")==null){
//                                        Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//
//                                    }else {
//                                        String message=jsonObject.getJSONObject("data").getJSONObject("data").getString("message");
//                                        int anInt=message.indexOf("：");
//                                        Log.e("anInt",""+anInt);
//                                        String myMessaye=message.substring(anInt+1,message.length());
//                                        Log.e("anInt",""+myMessaye);
//                                        myMessaye="用户账户余额不足，当前可用余额:"+String.valueOf(Double.parseDouble(myMessaye)/100+"元");
//                                        aralogid("提示",myMessaye);
//                                    }
//
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//
//                        } catch (UnsupportedEncodingException e) {
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        }
//                    }
//            }
//
//            @Override
//            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
//                Util.closeDialog(mydialog);
//            }
//        });
//    }
//    //掌财信用卡  直接提现
//    private void zhijietixian() {
//        AsyncHttpClient ahc = new AsyncHttpClient();
//        RequestParams params = new RequestParams();
//        params.put("user_id",user_id);
//        params.put("card_no",card_no);////付款卡
//        params.put("amount",money);//选中的卡有效期
//        Log.e("掌财信用卡提现params",params.toString());
//        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
//        ahc.post(Constant.TXZCT_URL, params, new AsyncHttpResponseHandler() {
//            @Override
//            public void onSuccess(int i, Header[] headers, byte[] bytes) {
//                Util.closeDialog(mydialog);
//                //判断状态码
//                if(i == 200){
//                    //获取结果
//                        try {
//                            String result = new String(bytes, "utf-8");
//                            //                        Toast.makeText(CreditRepayActivity.this, result, Toast.LENGTH_SHORT).show();
//                            Log.e("掌财信用卡提现Result", result);
//                            try {
//                                JSONObject jsonObject = new JSONObject(result);
//                                if (jsonObject.get("flag").equals("success")) {
//                                    finish();
//                                    Toast.makeText(CreditRepayActivity.this, "信用卡代还成功", Toast.LENGTH_LONG).show();
//                                } else {
//                                    if (jsonObject.getJSONObject("data").getJSONObject("data").getString("code")==null){
//                                        Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//
//                                    }else {
//                                        String message=jsonObject.getJSONObject("data").getJSONObject("data").getString("message");
//                                        int anInt=message.indexOf("：");
//                                        Log.e("anInt",""+anInt);
//                                        String myMessaye=message.substring(anInt+1,message.length());
//                                        Log.e("anInt",""+myMessaye);
//                                        myMessaye="用户账户余额不足，当前可用余额:"+String.valueOf(Double.parseDouble(myMessaye)/100+"元");
//                                        aralogid("提示",myMessaye);
//                                    }
//
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//
//                        } catch (UnsupportedEncodingException e) {
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        }
//                    }
//            }
//
//            @Override
//            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
//                Util.closeDialog(mydialog);
//            }
//        });
//    }
//    //掌财通信用卡还款 余额查询 +提现
//    private void yuesearch() {
//        AsyncHttpClient ahc = new AsyncHttpClient();
//        RequestParams params = new RequestParams();
//        params.put("user_id",user_id);
//        Log.e("掌财信用卡余额查询arams",params.toString());
//        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
//        ahc.post(Constant.QUERYYEZCT_URL, params, new AsyncHttpResponseHandler() {
//            @Override
//            public void onSuccess(int i, Header[] headers, byte[] bytes) {
//                //判断状态码
//                if(i == 200){
//                    //获取结果
//                        try {
//                            String result = new String(bytes, "utf-8");
//                            //                        Toast.makeText(CreditRepayActivity.this, result, Toast.LENGTH_SHORT).show();
//                            Log.e("掌财信用卡余额查询Result", result);
//                            try {
//                                JSONObject jsonObject = new JSONObject(result);
//                                if (jsonObject.get("flag").equals("success")) {
//                                  String availableamt=jsonObject.getJSONObject("data").getJSONObject("data").getString("availableamt");
//                                  String usedamt=jsonObject.getJSONObject("data").getJSONObject("data").getString("usedamt");
//                                    yueMoney=(Double.parseDouble(availableamt)-Double.parseDouble(usedamt))/100;
//                                    Log.e("yueMoney","yueMoney"+yueMoney);
//                                    tixian();
//                                } else {
//                                    Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//
//                        } catch (UnsupportedEncodingException e) {
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        }
//                    }
//            }
//
//            @Override
//            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
//                Util.closeDialog(mydialog);
//            }
//        });
//    }
//    //掌财通信用卡还款 余额查询(说明)
//    private void yuesearchSingle() {
//        AsyncHttpClient ahc = new AsyncHttpClient();
//        RequestParams params = new RequestParams();
//        params.put("user_id",user_id);
//        Log.e("掌财信用卡余额查询(说明)arams",params.toString());
//        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
//        ahc.post(Constant.QUERYYEZCT_URL, params, new AsyncHttpResponseHandler() {
//            @Override
//            public void onSuccess(int i, Header[] headers, byte[] bytes) {
//                Util.closeDialog(mydialog);
//                //判断状态码
//                if(i == 200){
//                    //获取结果
//                        try {
//                            String result = new String(bytes, "utf-8");
//                            //                        Toast.makeText(CreditRepayActivity.this, result, Toast.LENGTH_SHORT).show();
//                            Log.e("掌财信用卡余额查询(说明)Result", result);
//                            try {
//                                JSONObject jsonObject = new JSONObject(result);
//                                if (jsonObject.get("flag").equals("success")) {
//                                    JSONObject jsonObject1 = jsonObject.getJSONObject("data").getJSONObject("data");
//                                    String availableamt= jsonObject1.getString("availableamt");
//                                  String lastamt= jsonObject1.getString("lastamt");
//                                  String refundamt= jsonObject1.getString("refundamt");
//                                  String usedamt= jsonObject1.getString("usedamt");
//                                    yueMoney=(Double.parseDouble(availableamt)+Double.parseDouble(lastamt)+Double.parseDouble(refundamt)-Double.parseDouble(usedamt))/100;
//                                   String content="如果出现待查证、网络错误等问题造成代还失败，钱将会进入代还账户，您下一次只需要选择收款卡，即可将代还账户里的余额代还到您的信用卡。余额查询会有延迟，请过几分钟后进行查看。\n代还账户余额："+yueMoney+"元\n费率：0.55%+1";
//                                    aralogid("提示",content);
//                                } else {
//                                    Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//
//                        } catch (UnsupportedEncodingException e) {
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        }
//                    }
//            }
//
//            @Override
//            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
//                Util.closeDialog(mydialog);
//            }
//        });
//    }
//    //掌财通信用卡还款 更新费率
//    private void zctreChange() {
//        AsyncHttpClient ahc = new AsyncHttpClient();
//        RequestParams params = new RequestParams();
//        params.put("user_id",user_id);
//        Log.e("掌财信用卡更新费率arams",params.toString());
//        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
//        ahc.post(Constant.UPDATEZCT_URL, params, new AsyncHttpResponseHandler() {
//            @Override
//            public void onSuccess(int i, Header[] headers, byte[] bytes) {
//                Util.closeDialog(mydialog);
//                //判断状态码
//                if(i == 200){
//                    //获取结果
//                        try {
//                            String result = new String(bytes, "utf-8");
//                            //                        Toast.makeText(CreditRepayActivity.this, result, Toast.LENGTH_SHORT).show();
//                            Log.e("掌财信用卡更新费率Result", result);
//                            try {
//                                JSONObject jsonObject = new JSONObject(result);
//                                if (jsonObject.get("flag").equals("success")) {
//                                    chongzhi();
//                                } else {
//                                    Toast.makeText(CreditRepayActivity.this, jsonObject.getString("info"), Toast.LENGTH_LONG).show();
//
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//
//                        } catch (UnsupportedEncodingException e) {
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        }
//                    }
//            }
//
//            @Override
//            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
//                Util.closeDialog(mydialog);
//            }
//        });
//    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //        Log.e("RESPONSE_JIESHUAN",resultCode+"");
        if (resultCode==Constant.RESPONSE_ZCTCREPLAY){  // 选收款卡和付款卡
            listdata=(Data_bindcarlist)data.getSerializableExtra("listdata");
            String idcard=data.getStringExtra("card");
            phone=listdata.phone;
            expired_date=listdata.validthru;
            cvv=listdata.code;
            if (idcard.equals("fukuan")){
                pay_card_no=listdata.cardno;
                paylistdata=listdata;
                card=pay_card_no;
                zfcard_repaycreditard.setText(pay_card_no.substring(0, 4)+"    "+"***"+"    "+"***"+"    "+"***"+"    "+pay_card_no.substring(pay_card_no.length()-3,pay_card_no.length()));

            }else {
                shoulistdata=listdata;
                card_no=listdata.cardno;
                card=card_no;
                jscard_repaycredit.setText(card_no.substring(0, 4)+"    "+"***"+"    "+"***"+"    "+"***"+"    "+card_no.substring(card_no.length()-3,card_no.length()));
            }
//        bindsendm();
        }else if(resultCode==Constant.RESPONSE_CJKJZFBIND){
                smsCode_bind=data.getStringExtra("smsCode_bind");
        }
    }
//    AlertDialog alertDialog;
//
//    private void aralogid(String info, String kll) {
//        alertDialog = new AlertDialog.Builder(CreditRepayActivity.this).
//                setTitle(info).
//                setMessage(kll).
//                setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        if(yueMoney>0){
//                            money_repaycreditard_et.setText(yueMoney+"");
//                        }
//                        alertDialog.dismiss();
//                    }
//                }).create();
//        alertDialog.show();
//    }
//    private void flaralogid(String info, String kll) {
//        alertDialog = new AlertDialog.Builder(CreditRepayActivity.this).
//                setTitle(info).
//                setMessage(kll).
//                setPositiveButton("重试", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        mydialog=Util.createLoadingDialog(CreditRepayActivity.this);
//                        zctreChange();
//                    }
//                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        alertDialog.dismiss();
//                    }
//                }).create();
//        alertDialog.show();
//    }
    //高汇通快捷支付预下单
    private void  yOrder() {
        AsyncHttpClient ahc = new AsyncHttpClient();
        RequestParams params = new RequestParams();
        params.put("user_id",user_id);
        params.put("card_no",pay_card_no);
        params.put("way",way_id);
        params.put("amount",money);
        params.put("other_card_no",card_no);
        Log.e("高汇通快捷支付预下单url",Constant.GHTYZF_URL);
        Log.e("高汇通快捷支付预下单params",params.toString());
        //url:   parmas：请求时携带的参数信息   responseHandler：是一个匿名内部类接受成功过失败
        ahc.post(Constant.GHTYZF_URL, params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, byte[] bytes) {
                //判断状态码
                if(i == 200){
                    //获取结果
                    try {
                        String result = new String(bytes, "utf-8");
                        //                        Toast.makeText(GhtSelectActivity.this, result, Toast.LENGTH_SHORT).show();
                        Log.e("高汇通快捷支付预下单Result", result);
                        try {
                            JSONObject jsonObject = new JSONObject(result);
                            if (jsonObject.get("flag").equals("success")) {
                                JSONObject jsonObject1 = jsonObject.getJSONObject("data").getJSONObject("data");
                                String dealcode = jsonObject1.getString("dealcode");
                                if (dealcode.equals("10000")){
                                    String orderno=jsonObject1.getString("orderno");
                                    String needsms=jsonObject1.getString("needsms");
                                    Util.closeDialog(mydialog);
                                    if (needsms.equals("0")){
                                        tishi("抱歉，该通道暂不支持该银行卡");
                                        //                                        Intent intent=new Intent(GhtSelectActivity.this,GhtZfActivity.class);
                                        //                                        intent.putExtra("paylistdata",payListdata);
                                        //                                        intent.putExtra("listdata",listdata);
                                        //                                        intent.putExtra ("money",money);
                                        //                                        intent.putExtra ("way_id",way_id);
                                        //                                        intent.putExtra ("orderno",orderno);
                                        //                                        startActivity(intent);
                                    } else if (needsms.equals("1")) {
                                        Intent intent=new Intent(CreditRepayActivity.this,GhtZfActivity.class);
                                        intent.putExtra("paylistdata",paylistdata);
                                        intent.putExtra("listdata",shoulistdata);
                                        intent.putExtra ("money",money);
                                        intent.putExtra ("way_id",way_id);
                                        intent.putExtra ("orderno",orderno);
                                        startActivity(intent);
                                    }
                                }else {
                                    tishi(jsonObject1.getString("dealmsg"));
                                }

                            } else {
                                Util.closeDialog(mydialog);
                                String info = jsonObject.getString("info");
                                if (jsonObject.has("data")){
                                    info=jsonObject.getJSONObject("data").getJSONObject("data").getString("dealmsg");
                                }
                                tishi(info);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                Util.closeDialog(mydialog);
            }
        });
    }
}
